package com.app.bd;

import com.app.entidades.Bar;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class BarBD {

	private SQLiteDatabase database;
	private DbHelper dbHelper;
	private String[] allColumns = { DbHelper.id, DbHelper.nome, DbHelper.endereco,
	DbHelper.desc_p, DbHelper.logotipo, DbHelper.descricao, DbHelper.horarios, DbHelper.fone,DbHelper.email
	,DbHelper.site,DbHelper.tw,DbHelper.fb,DbHelper.foursquare};
	
	public BarBD(Context context) {          
		dbHelper = new DbHelper(context);
		database = dbHelper.getWritableDatabase();
	}

	public Bar createBar(String nome, String endereco, String desc_p, String logotipo, String descricao, String horarios, String fone
		, String email, String site, String tw, String fb, String foursquare) { 
        ContentValues values = new ContentValues(); 
        values.put(DbHelper.nome, nome);
        values.put(DbHelper.endereco, endereco); 
        values.put(DbHelper.desc_p, desc_p); 
        values.put(DbHelper.logotipo, logotipo); 
        values.put(DbHelper.descricao, descricao); 
        values.put(DbHelper.horarios, horarios); 
        values.put(DbHelper.fone, fone); 
        values.put(DbHelper.email, email); 
        values.put(DbHelper.site, site); 
        values.put(DbHelper.tw, tw); 
        values.put(DbHelper.fb, fb); 
        values.put(DbHelper.foursquare, foursquare); 
        long insertId = database.insert(DbHelper.TABLE_NAME_BARES, null, values); 
       
       Cursor cursor = database.query(DbHelper.TABLE_NAME_BARES, allColumns, DbHelper.id + " = " + 
       insertId, null,null, null, null); 
       cursor.moveToFirst(); 
       return cursorToBar(cursor); 
	}
	
   private Bar cursorToBar(Cursor cursor) { 
        Bar bar = new Bar(cursor.getInt(0),cursor.getString(1),cursor.getString(2),cursor.getString(3)
        		, cursor.getString(4),cursor.getString(5),cursor.getString(6),cursor.getString(7)
        		, cursor.getString(8),cursor.getString(9)
        		, cursor.getString(10),cursor.getString(11)
        		, cursor.getString(12)); 
        return bar; 
   }
}
